import React, { Component } from 'react';
import empty from '../../assets/images/blankcart.jpg'
import {NavBar} from 'antd-mobile'
import './Cart.scss'

class Cart extends Component {
    state = {
        carts: []
    }
    // 获取本地缓存中的购物车数据
    componentDidMount() {
        let carts_str = localStorage.getItem('carts');
        let carts = JSON.parse(carts_str || '[]');
        this.setState({
            carts
        })
    }
    render() {
        return (
            <div className='yg-cart'>
                {
                    !!this.state.carts.length ? (
                        <div className="yg-cart-content">
                            <div>
                                <NavBar className="cart-content-nav">优购商城</NavBar>
                            </div>
                            {/* 购物车列表 */}
                            <div className="cart-content-list">
                                {this.state.carts.map((v, index) => {
                                    return <div className="content-list-item" key={v.goods_id}>
                                        <div className="list-item-left">
                                            <i className="iconfont icon-shanchu-xuanzhong"></i>
                                        </div>
                                        <div className="list-item-mid"><img src={v.goods_small_logo} alt="" /></div>
                                        <div className="list-item-right">
                                            <div className="right-top">
                                                <div className="right-top-title">{v.goods_name}</div>
                                                <div className="right-bottom">
                                                    <div className="right-bottom-left">￥{v.goods_price}</div>
                                                    <div className="right-bottom-right">
                                                        <i className="iconfont icon-iconset0187"></i>
                                                        <span className='num'>{v.num}</span>
                                                        <i className='iconfont icon-icon-'></i>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                }
                                )}
                            </div>
                            {/* 购物车列表 */}
                            {/* 底栏结算 */}
                            <div className="cart-content-bottom">
                                <div className="all-checked">
                                    <i className="circle"></i>
                                    <span className='text'>全选</span>
                                </div>
                                <div className="totalPrice">
                                    <span className="text1">合计</span>
                                    <span className="price">￥6699</span>
                                </div>
                                <div className="pay">
                                    <span className="text3">去结算(1)</span>
                                </div>
                            </div>
                            {/* 底栏结算 */}


                        </div>
                    ) : <div className='yg-cart-empty'><img className='cart-empty-img' src={empty} alt="" />
                            <h3 className='empty_text'><a href="#/category">去逛逛~</a></h3>
                        </div>
                }
            </div>
        );
    }
}

export default Cart;
